// Copyright (c) Microsoft Corporation.  All rights reserved.

#include "stdafx.h"
#include "D3D10EffectPass.h"

#include "D3D10EffectVariable.h"
using namespace Microsoft::WindowsAPICodePack::DirectX::Direct3D10;
using namespace msclr::interop;

void EffectPass::Apply(UInt32 Flags)
{
    CommonUtils::VerifyResult(GetInterface<ID3D10EffectPass>()->Apply(static_cast<UINT>(Flags)));
}

StateBlockMask^ EffectPass::ComputeStateBlockMask()
{
    D3D10_STATE_BLOCK_MASK* blockMask = new D3D10_STATE_BLOCK_MASK();
    ZeroMemory(blockMask, sizeof(D3D10_STATE_BLOCK_MASK));

    CommonUtils::VerifyResult(GetInterface<ID3D10EffectPass>()->ComputeStateBlockMask(blockMask));

    return gcnew StateBlockMask(blockMask);
}

EffectVariable^ EffectPass::GetAnnotationByIndex(UInt32 index)
{
    ID3D10EffectVariable* returnValue = GetInterface<ID3D10EffectPass>()->GetAnnotationByIndex(static_cast<UINT>(index));
    return gcnew EffectVariable(returnValue);
}

EffectVariable^ EffectPass::GetAnnotationByName(String^ name)
{
    marshal_context^ context = gcnew marshal_context();
    return gcnew EffectVariable(GetInterface<ID3D10EffectPass>()->GetAnnotationByName(context->marshal_as<const char*>(name)));
}

PassDescription^ EffectPass::GetDescription()
{
    PassDescription^ desc = gcnew PassDescription();

    CommonUtils::VerifyResult(GetInterface<ID3D10EffectPass>()->GetDesc(desc->nativeObject.Get()));
    
    return desc;
}

PassShaderDescription^ EffectPass::GetGeometryShaderDescription()
{

    PassShaderDescription^ desc = gcnew PassShaderDescription();

    CommonUtils::VerifyResult(GetInterface<ID3D10EffectPass>()->GetGeometryShaderDesc(desc->nativeObject.Get()));

    return desc;
}

PassShaderDescription^ EffectPass::GetPixelShaderDescription()
{
    PassShaderDescription^ desc = gcnew PassShaderDescription();

    CommonUtils::VerifyResult(GetInterface<ID3D10EffectPass>()->GetPixelShaderDesc(desc->nativeObject.Get()));

    return desc;
}

PassShaderDescription^ EffectPass::GetVertexShaderDescription()
{
    PassShaderDescription^ desc = gcnew PassShaderDescription();

    CommonUtils::VerifyResult(GetInterface<ID3D10EffectPass>()->GetVertexShaderDesc(desc->nativeObject.Get()));

    return desc;
}

Boolean EffectPass::IsValid::get()
{
    return GetInterface<ID3D10EffectPass>()->IsValid() != 0;
}

